package com.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQConfig {

    public static final String DIRECT_EXCHANGE = "s20202_DirectExchange";
    public static final String QUEUE_MIAOSHA = "s20202_QUEUE_MIAOSHA";
    public static final String QUEUE_SENDMESSAGE = "QUEUE_SENDMESSAGE";
    public static final String KEY_MIAOSHA = "s20202_KEY_MIAOSHA";
    public static final String KEY_SENDMESSAGE = "s20202_KEY_SENDMESSAGE";

    /**
     * 直接型交换机
     * @return
     */
    @Bean
    public DirectExchange  createDirectExchange()
    {
        return new DirectExchange(DIRECT_EXCHANGE);
    }

    /**
     * 这是主题交换机
     * @return
     */
    @Bean
    public TopicExchange  createTopicExchange()
    {
        return new TopicExchange("这是主题交换机");
    }

    /**
     * 创建秒杀队列
     * @return
     */
    @Bean
    public Queue createQueueQ_UEUE_MIAOSHA()
    {
        return new Queue(QUEUE_MIAOSHA);
    }

    /**
     * 创建发消息队列
     * @return
     */
    @Bean
    public Queue createQueueQ_QUEUE_SENDMESSAGE()
    {
        return new Queue(QUEUE_SENDMESSAGE);
    }

    /**
     * 直连交换机绑定秒杀队列
     * @return
     */
    @Bean
    public Binding bindng________DIRECT_EXCHANGE_____________MIAOSHA()
    {
        return BindingBuilder.bind(createQueueQ_UEUE_MIAOSHA()).to(createDirectExchange()).with(KEY_MIAOSHA);
    }


    /**
     * 直连交换机绑定秒杀队列
     * @return
     */
    @Bean
    public Binding bindng_________DIRECT_EXCHANGE__________SENDMESSAGE()
    {
        return BindingBuilder.bind(createQueueQ_QUEUE_SENDMESSAGE()).to(createDirectExchange()).with(KEY_SENDMESSAGE);
    }


    @Bean
    public Binding bindng_________TopicExchange__________SENDMESSAGE()
    {
        return BindingBuilder.bind(createQueueQ_QUEUE_SENDMESSAGE()).to(createTopicExchange()).with("com.#");
    }







}
